package edu.ustb.utils;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public interface JsonUtil {

    static JSONObject toJSONOb(ServletInputStream inputStream) throws IOException {
        //获得json字符串，json字符串-》json对象-》java对象
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
        String line;
        StringBuilder sb = new StringBuilder();
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        System.out.println("json工具类"+sb.toString());
        //字符串转换json对象。
        JSONObject jsonObject = JSONObject.parseObject(sb.toString());
        return jsonObject;
    }
}
